package com.changil.admin.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.changil.admin.action.Action;
import com.changil.admin.action.board.DeleteAction;
import com.changil.admin.action.board.ListAction;
import com.changil.admin.action.board.ModifyAction;
import com.changil.admin.action.board.ModifyFormAction;
import com.changil.admin.action.board.ViewAction;
import com.changil.admin.action.board.WriteAction;
import com.changil.admin.action.board.WriteFormAction;

public class BoardServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");

		String a = request.getParameter("a");
		if (a == null) {
			a = "";
		}
		int boardId = Integer.parseInt(request.getParameter("boardId"));

		Action action = null;
		if (a.equals("writeform")) {
			action = new WriteFormAction(boardId);
		} else if (a.equals("write")) {
			action = new WriteAction(boardId);
		} else if (a.equals("delete")) {
			action = new DeleteAction(boardId);
		} else if (a.equals("view")) {
			action = new ViewAction(boardId);
		} else if (a.equals("modifyform")) {
			action = new ModifyFormAction(boardId);
		} else if (a.equals("modify")) {
			action = new ModifyAction(boardId);
		} else {
			action = new ListAction(boardId);
		}

		if (action != null) {
			action.execute(request, response);
		}
	}

}
